package server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ConcurrentHashMap;

import socket.SocketStream;
import utility.Constant;

public class TCPServer {
	
	private ServerSocket server_socket;
	private ConcurrentHashMap<String,SocketStream> map_userid_socketstream;
	private int client_count = 0;
	
	public TCPServer(){
		try {
			this.server_socket = new ServerSocket(Constant.SERVER_PORT);
			this.map_userid_socketstream = new ConcurrentHashMap<String,SocketStream>();
			while(true){
				System.out.println("server is waitting...");
				Socket socket_to_client = this.server_socket.accept();
				System.out.println("client "+(++client_count)+" creadted");
				new ServerReceivePacketThread(new SocketStream(socket_to_client),this.map_userid_socketstream).start();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		new TCPServer();
	}

}
